<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!-- START 右侧数据 -->

            <!-- START 操作按钮 -->
            <form>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">

                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-download" aria-hidden="true"></i> 获取数据
                </button>
            </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-page-size="15"
                   data-url="/sea/operate/wordClick/findByCnd.do"
                   class="table table-striped table-hover">
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>


<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>


    var $relatedTable = $('#relatedTable'),selections=[];
    $(function(){
        //指定允许上传的文件类型
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: 'Asin',
                    field: 'asin',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'SearchTerm',
                    field: 'search_query',
                    align: 'center',
                    valign: 'middle'
                }
            ],
            onLoadSuccess : function(){

                //修改
                $('.edit-related-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    $("#id").val(id);
                    var name=$(this).attr("data-listing");
                    $("#editListing").val(name);
                    var asin=$(this).attr("data-asin");
                    if('null'==asin){
                        $("#editAsin").val('');
                    }else{
                        $("#editAsin").val(asin);
                    }

                    layer.open({
                        type:1,
                        title:'修改Listing',
                        area:['600px','250px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_edit_window')
                    })
                });
            },
            onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });
    });
    //操作菜单
    function optFormatter(value,row){
        var content = '<button class="edit-related-btn btn btn-xs btn-info" data-asin="'+row.relatedAsin+'" data-listing="'+row.relatedListing+'" data-val="'+row.id+'" title="修改"><i class="fa fa-edit"></i>  </button>';
        return content;
    }

    $('.add-btn').on('click',function(){//新增
        layer.open({
            type:1,
            title:'添加Listing',
            area:['600px','300px'],
            skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
            shadeClose:false,
            resize: false,
            scrollbar: false,
            maxmin: false,//出现最大化按钮
            content:$('#layer_window')
        })
    });
    //提交表单
    $('.save-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var relatedChannelName=$("#relatedChannelName").val();
            if(relatedChannelName==''){
                parent.layer.msg('请选择渠道！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedListing=$("#relatedListing").val();
            if(relatedListing==''){
                parent.layer.msg('请填写Listing名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedAsin=$("#relatedAsin").val();
            if(relatedAsin==''){
                parent.layer.msg('请填写Asin名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/operate/related/save.do',{relatedAsin:relatedAsin,relatedListing:relatedListing,relatedChannelName:relatedChannelName},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    //提交表单
    $('.edit-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var relatedListing=$("#editListing").val();
            if(relatedListing=='' || relatedListing ==null){
                parent.layer.msg('请填写Listing名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedAsin=$("#editAsin").val();
            if(relatedAsin=='' || relatedAsin ==null){
                parent.layer.msg('请填写Asin名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/operate/related/usave.do',{id:$("#id").val(),relatedAsin:relatedAsin,relatedListing:relatedListing},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    $('.search-btn').on('click',function(){
           $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/operate/related/findByCnd.do?'+$('#search-form').serialize() });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/operate/wordClick/export.do?'+$('#search-form').serialize();
    });


</script>
</body>
</html>
